package com.hybs.controller;/*
 * @author: Hayabusa
 * @date: 2021/9/14 23:04
 * @Description:
 * @Email:2682557218@qq.com
 */

import com.hybs.entity.Product;
import com.hybs.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Value("${server.port}")
    private String port;
    @Value("${spring.cloud.client.ip-address}")
    private  String ip;
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Product findById(@PathVariable Long id){
        Product product=productService.findById(id);
        product.setProductName("访问的服务地址"+ip+":"+port);
        return product;

    }

    @RequestMapping(value = "/{id}",method = RequestMethod.POST)
    public String save(@RequestBody Product product){
        productService.save(product);
        return "保存成功";

    }

}
